import 'package:boss/provider/cloud_printer_provider.dart';
import 'package:boss/ui/page/printer/constant/printer_constant.dart';
import 'package:boss/ui/widget/button/fixed_bottom_btn.dart';
import 'package:boss/ui/widget/form/base_text_form_field.dart';
import 'package:boss/ui/widget/form/select_form_field.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class PrinterStepOneBrowser extends StatefulWidget {
  @override
  _PrinterStepOneBrowserState createState() => _PrinterStepOneBrowserState();
}

class _PrinterStepOneBrowserState extends State<PrinterStepOneBrowser> {
  List<SelectItem<String>> brands = [
    SelectItem(title: '飞鹅', value: '飞鹅'),
//    SelectItem(title: '中琦', value: '中琦'),
//    SelectItem(title: '佳博', value: '佳博'),
    SelectItem(title: '商米', value: '商米'),
  ];

  List<SelectItem<int>> pagerWidths = [
    SelectItem(title: '57', value: 57),
    SelectItem(title: '58', value: 58),
    SelectItem(title: '80', value: 80),
  ];

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Expanded(
          child: SingleChildScrollView(
              padding: EdgeInsets.symmetric(
                horizontal: 30.w,
              ),
              child: Consumer<CloudPrinterProvider>(
                builder: (context, provider, child) {
                  return Column(
                    children: <Widget>[
                      BaseTextFormField(
                        prefixText: '打印机名称',
                        hintText: '请输入',
                        isRequired: true,
                        initialValue: provider.editCloudPrinter.printerName,
                        onChanged: (value) {
                          provider.editCloudPrinter.printerName = value;
                        },
                      ),
                      BaseTextFormField(
                        prefixText: '编号（SN）',
                        hintText: '请输入',
                        isRequired: true,
                        onChanged: (value) {
                          provider.editCloudPrinter.cloudSn = value;
                        },
                        initialValue: provider.editCloudPrinter.cloudSn,
                      ),
                      if (provider.editCloudPrinter.printerBrand != PrinterConstant.SHANG_M_NAME)
                        BaseTextFormField(
                          prefixText: '密钥（KEY）',
                          hintText: '请输入',
                          isRequired: true,
                          onChanged: (value) {
                            provider.editCloudPrinter.cloudKey = value;
                          },
                          initialValue: provider.editCloudPrinter.cloudKey,
                        ),
                      SelectFormField<String>(
                        title: '品牌',
                        items: brands,
                        hintText: '请选择',
                        onChanged: (value) {
                          provider.setBrand(value);
                        },
                        value: provider.editCloudPrinter.printerBrand,
                      ),
                      SelectFormField<int>(
                        title: '纸张宽度',
                        items: pagerWidths,
                        hintText: '请选择',
                        onChanged: (value) {
                          provider.setPageWidth(value);
                        },
                        value: provider.editCloudPrinter.paperWidth,
                      ),
                    ],
                  );
                },
              )),
        ),
        Consumer<CloudPrinterProvider>(
          builder: (context, provider, child) {
            return FixedBottomBtn(
              title: provider.isEdit ? '保存' : '下一步，设置打印机',
              onTap: () {
                var provider = Provider.of<CloudPrinterProvider>(context, listen: false);
                provider.nextStep();
              },
            );
          },
        ),
      ],
    );
  }
}
